import java.util.*;

public class HashMapTest {
    public static void main(String[] args) {
        HashMap<Integer, String> hashMap = new HashMap<>();

        hashMap.put(2, "秦浩泽");
        hashMap.put(12, "李俊佳");
        hashMap.put(11, "赵雪");
        hashMap.put(8, "潘家乐");

        // 获取所有的key
        Set<Integer> keySet = hashMap.keySet();
        Iterator<Integer> iterator = keySet.iterator();
        while (iterator.hasNext()) {
            System.out.println(iterator.next());
        }

        // 获取所有的values
        Collection<String> values = hashMap.values();
        Iterator<String> iterator1 = values.iterator();
        while (iterator1.hasNext()) {
            System.out.println(iterator1.next());
        }

        // 获取所有的keys和values，返回的是 Set
        Set<Map.Entry<Integer, String>> entrySet = hashMap.entrySet();
        Iterator<Map.Entry<Integer, String>> iterator2 = entrySet.iterator();
        while (iterator2.hasNext()) {
            System.out.println(iterator2.next());
        }

        HashMap<Integer, String> map = new HashMap<>();
        map.put(15,"代晨阳");

        hashMap.putAll(map);

        int size = hashMap.size();
        System.out.println("size = " + size);

        hashMap.remove(15, "代晨阳");
        size = hashMap.size();
        System.out.println("size = " + size);

        map.clear();
        int i = map.size();
        System.out.println("i = " + i);

        String s = hashMap.get(2);
        System.out.println("s = " + s);

        boolean key = hashMap.containsKey(13);
        System.out.println("key = " + key);
        boolean value = hashMap.containsValue("潘家乐");
        System.out.println("value = " + value);

        boolean empty = map.isEmpty();
        System.out.println("empty = " + empty);

        boolean equals = hashMap.equals(map);
        System.out.println("equals = " + equals);
    }
}
